﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace MoetutuTranslate.Helper
{
    class XmlHelper
    {


        public static void CreateXML(string FileName)
        {
            FileHelper.FloderExits(Path.GetDirectoryName(FileName), true);
            if (!FileHelper.FileExits(FileName))
            {

                XmlDocument xml = new XmlDocument();


                XmlDeclaration decl = xml.CreateXmlDeclaration("1.0", "utf-8", null);
                xml.AppendChild(decl);


                XmlElement rootEle = xml.CreateElement("Root");
                xml.AppendChild(rootEle);


                xml.Save(FileName);
            }


        }
        public static void AppendXml(String FileName, String ParentPath, XmlElement ChildrenNode)
        {

            if (!FileHelper.FileExits(FileName))
                CreateXML(FileName);

            XmlDocument xml = new XmlDocument();
            xml.Load(FileName);
            xml.SelectSingleNode(ParentPath).AppendChild(ChildrenNode);
            xml.Save(FileName);

        }
    }
}
